const db = require('./db/dbconfig.js');

async function debugLogin() {
  try {
    console.log('=== 数据库用户数据检查 ===');
    const users = await db.query('SELECT user_id, username, password, LENGTH(password) as pwd_len FROM users');
    console.log('用户数据:', JSON.stringify(users, null, 2));
    
    console.log('\n=== 测试用户ID 1 (用户名: 70) ===');
    const user1 = await db.query('SELECT * FROM users WHERE username = ?', ['70']);
    console.log('用户70的数据:', JSON.stringify(user1, null, 2));
    
    console.log('\n=== 测试用户ID 3 (用户名: test) ===');
    const user3 = await db.query('SELECT * FROM users WHERE username = ?', ['test']);
    console.log('用户test的数据:', JSON.stringify(user3, null, 2));
    
    console.log('\n=== 密码格式分析 ===');
    users.forEach(user => {
      const password = user.password || user[0]?.password;
      const username = user.username || user[0]?.username;
      if (password) {
        console.log(`用户 ${username}: 密码长度 ${password.length}, 是否bcrypt格式: ${password.startsWith('$2')}`);
      }
    });
    
  } catch (error) {
    console.error('调试错误:', error);
  }
}

debugLogin();